<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
 "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
	xmlns:ui="http://java.sun.com/jsf/facelets"
	xmlns:h="http://java.sun.com/jsf/html"
	xmlns:f="http://java.sun.com/jsf/core"
	xmlns:p="http://primefaces.org/ui">

<h:head>
	<title>Grade horária</title>
	<h:outputStylesheet library="css" name="style.css" />
	<h:outputScript name="jsf.js" library="javax.faces" target="head" />
</h:head>
<h:body>
	<div id="cabecalho" align="center">
		<p:panel id="pn">
			<h:graphicImage library="imagens" name="logo.gif" id="logoCompany" />
			<h2>
				Sistema Estatistico
				<p:separator></p:separator>
			</h2>
			<p:commandButton value="Iniciar" action="#{formularioBean.iniciar}"
				actionListener="#{formularioBean.limpar}" update=":form pn"
				immediate="true" rendered="#{formularioBean.iniciado == false}"></p:commandButton>
		</p:panel>
	</div>

	<h:form id="form">
		<p:messages autoUpdate="true"></p:messages>
		<div align="center">
			<p:panelGrid columns="1" style="width:80%"
				rendered="#{formularioBean.iniciado == true}">
				<f:facet name="header">  
Questionário
    </f:facet>

				<p:dataList id="tabelaQuestoes" var="questao"
					value="#{formularioBean.listaQuestoes}" type="ordered"
					style="width:100%">

					<p:panel rendered="#{questao.alternativas.size() > 1}">
						<p:column headerText="Model">
							<f:facet name=""></f:facet>
							<h:outputText value="#{questao.enunciado}" />
							<br />
							<br />
							<p:selectOneListbox id="opcao" style="width:90%;"
								rendered="#{questao.alternativas.size() >3}"
								value="#{formularioBean.alternativaSelecionada}"
								converter="alternativaConverter" required="true"
								requiredMessage="Você esqueceu de responder esta questão: #{questao.enunciado}">
								<f:selectItems value="#{questao.alternativas}"
									var="alternativas" itemLabel="#{alternativas.descricao}"
									itemValue="#{alternativas}" />
								<p:ajax update="opcao"
									listener="#{formularioBean.addAlternativa}"></p:ajax>
							</p:selectOneListbox>
							<p:selectOneButton id="opcao2" style="width:90%;"
								rendered="#{questao.alternativas.size() == 3 or questao.alternativas.size() == 2 or questao.alternativas.size() == 1}"
								value="#{formularioBean.alternativaSelecionada}"
								converter="alternativaConverter" required="true"
								requiredMessage="Você esqueceu de responder esta questão: #{questao.enunciado}">
								<f:selectItems value="#{questao.alternativas}"
									var="alternativas" itemLabel="#{alternativas.descricao}"
									itemValue="#{alternativas}" />
								<p:ajax update="opcao2"
									listener="#{formularioBean.addAlternativa}"></p:ajax>
							</p:selectOneButton>


						</p:column>
						<p:separator></p:separator>

						<br />
					</p:panel>
				</p:dataList>
				<f:facet name="footer">
					<div align="center">
						<p:commandButton value="Finalizar"
							action="#{formularioBean.finalizarQuestionario}"
							update="tabelaQuestoes"></p:commandButton>
					</div>
				</f:facet>
			</p:panelGrid>

		</div>

	</h:form>

</h:body>
</html>